package com.food.controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.food.model.Course;
import com.food.dao.service.CourseService;

/**
 * Servlet implementation class DisplayCourse
 */
@WebServlet("/course/DisplayCourse")
public class DisplayCourse extends HttpServlet {
	private static final long serialVersionUID = 1L;

    public DisplayCourse() {
        // TODO Auto-generated constructor stub
    }
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try{
		if(request.getParameter("type").equals("MANAGER")){
			CourseService service = new CourseService();
			Collection<Course> coll = service.findAllCourse();
			request.setAttribute("products_DPP", coll);
			RequestDispatcher rd = request
					.getRequestDispatcher("/manager/managecourse.jsp");
			rd.forward(request, response);
			return;
			
		}
		}
		catch(Exception e){
		
		CourseService service = new CourseService();
		Collection<Course> coll = service.findAllCourse();
		request.setAttribute("products_DPP", coll);
		RequestDispatcher rd = request
				.getRequestDispatcher("/course/course.jsp");
		rd.forward(request, response);
		return;
		}
		
	}

}
